<template>
	<div>
		<AplidForm ref="formRef" v-bind="BaseFormConfig" v-model="formModel" @submit="onSubmit" @reset="back">
		</AplidForm>
	</div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { ElMessageBox } from 'element-plus'
import apiMod from '@/apiMod'
import { uploadType } from '@/utils/util'
import { getStore } from '@/utils/store'
const emit = defineEmits(['refresh', 'back'])

type Props = {
	newData?: any
}
let props = withDefaults(defineProps<Props>(), {
	newData: {},
})
let formKey = ref(0)
// 获取当前用户的统一信用代码
let creditCode = ref('')
creditCode.value = getStore('userInfo').organizationId

let formModel: any = ref({})
let formRef = ref()

let BaseFormConfig = {
	inline: false,
	labelPosition: 'left',
	labelWidth: 170,
	column: [
		{
			type: 'DividerHtml',
			modelValue: '员工信息',
			labelPosition: 'top',
			span: 24,
		},
		{
			label: '员工姓名',
			prop: 'idCard',
			propName: 'practitionersName',
			type: 'autoSelect',
			api: 'view_dpFoundationPractitioners_page',
			filterKey: 'idCard',
			filterLabel: 'practitionersName',
			paramsObj: { creditCode: creditCode.value },
			span: 12,
			rules: [{ required: true, message: '请选择员工姓名' }],
			change: (item, form, value) => {
        form.laborContract = item.material
			  handleGetProjectInfo(item)
			},
		},
		{ label: '身份证号', prop: 'idCard', span: 12, rules: [{ required: true, message: '请填写身份证号' }] },
		{
			label: '联系方式',
			prop: 'phone',
			span: 12,
			rules: [{ required: true, message: '请填写联系方式' }],
		},
		{
			type: 'DividerHtml',
			modelValue: '入职信息',
			labelPosition: 'top',
			span: 24,
		},

		{
			label: '入职时间',
			prop: 'entryDate',
			type: 'date',
			format: 'YYYY年MM月DD ',
			valueFormat: 'YYYY-MM-DD',
			span: 12,
			rules: [{ required: true, message: '请选择入职时间' }],
		},
		{
			label: '岗位类型',
			prop: 'postType',
			propName: 'postTypeLabel',
			type: 'remoteSelect',
			api: 'getDictItemList',
			code: 'POSITION_TYPE',
			span: 12,
			rules: [{ required: true, message: '请选择岗位类型' }],
		},
		{
			label: '职业类型',
			prop: 'jobType',
			propName: 'jobTypeLabel',
			type: 'remoteSelect',
			api: 'getDictItemList',
			code: 'OCCUPATION_TYPE',
      multiple: true,
			span: 12,
			rules: [{ required: true, message: '请选择职业类型' }],
		},
		{
			label: '聘用方式',
			prop: 'hireMode',
			propName: 'hireModeLabel',
			type: 'remoteSelect',
			api: 'getDictItemList',
			code: 'HIRE_MODE',
			span: 12,
			rules: [{ required: true, message: '请选择聘用方式' }],
		},
		{
			label: '合同到期时间',
			prop: 'contractExpirationDate',
			type: 'date',
			format: 'YYYY年MM月DD ',
			valueFormat: 'YYYY-MM-DD',
			span: 12,
			rules: [{ required: true, message: '请选择合同到期时间' }],
		},
		{
			label: '入职协议（劳动合同）',
			prop: 'laborContract',
			type: 'upload',
			fileType: uploadType.fileMetaType,
			listType: 'picture-card',
			labelPosition: 'top',
			showFileList: true,
			limit: 4,
			multiple: true,
			span: 24,
			rules: [{ required: true, message: '请上传入职协议（劳动合同）' }],
		},
	],
}

const handleGetProjectInfo = (item?:any) => {
  if(!item) item = {}
  console.log(item,'item----')
	formModel.value.jobType = item.occupationType
	formModel.value.jobTypeLabel = item.occupationTypeLabel
	formModel.value.gender = item.gender
	formModel.value.genderLabel = item.genderLabel
	formModel.value.postType = item.positionType
	formModel.value.postTypeLabel = item.positionTypeLabel

	formModel.value.idCard = item.idCard
	formModel.value.creditCode = creditCode.value
	formModel.value.practitionersName = item.practitionersName
	formModel.value.phone = item.phone
	formModel.value.belongUnit = item.unitName
	formModel.value.certificateType = item.certificateType
	formModel.value.certificateTypeLabel = item.certificateTypeLabel
	// formKey.value = Math.random()
}
const onSubmit = (form, done) => {
	apiMod
		.view_dpPractitionersExperience_entry(form)
		.then((res) => {
			done()
			emit('refresh')
		})
		.catch(() => {
			done()
		})
}
const back = () => {
	emit('back')
}

const onSave = () => {
	formRef.value!.onSubmit()
}
defineExpose({
	onSave,
})
</script>

<style scoped></style>
